/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CustomerSearchCondition;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.db.TagManager;
/*     */ import com.newcrm.exception.DBException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.List;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class AddCustomerTagRelation extends AbstractAction
/*     */ {
/*  28 */   private static Logger logger = Logger.getLogger(AddCustomerTagRelation.class.getName());
/*     */ 
/*     */   public AddCustomerTagRelation(AbstractHttpServlet servlet) {
/*  31 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException
/*     */   {
/*  38 */     int tagId = Util.getURLIntParameter(request.getParameter("TagId"));
/*  39 */     int customerId = Util.getURLIntParameter(request
/*  40 */       .getParameter("CustomerId"));
/*     */ 
/*  42 */     String type = Util.getURLParameter(request.getParameter("Type"));
/*  43 */     String customerIds = Util.getURLParameter(request
/*  44 */       .getParameter("CustomerIds"));
/*  45 */     String selectAll = Util.getURLParameter(request
/*  46 */       .getParameter("selectAll"));
/*     */ 
/*  48 */     User loginUser = super.getLoginUser(request);
/*  49 */     String userId = loginUser.userId;
/*  50 */     int companyId = loginUser.companyId;
/*     */ 
/*  52 */     response.setContentType("text/html;charset=utf-8");
/*  53 */     PrintWriter out = response.getWriter();
/*  54 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/*  57 */     if ("1".equals(selectAll)) {
/*  58 */       CustomerSearchCondition searchCondition = new CustomerSearchCondition(
/*  59 */         request, loginUser, false);
/*  60 */       CustomerManager manager = new CustomerManager();
/*  61 */       List allCustomerIds = null;
/*     */       try
/*     */       {
/*  64 */         allCustomerIds = manager.getAllSelectedCustomerId(
/*  65 */           searchCondition, loginUser);
/*  66 */         if (allCustomerIds != null) {
/*  67 */           TagManager tagManager = new TagManager();
/*     */ 
/*  69 */           int result = tagManager.addAll(tagId, allCustomerIds, 
/*  70 */             companyId, userId);
/*  71 */           jsonObject.put("error", "0");
/*  72 */           jsonObject.put("updateNum", Integer.valueOf(result));
/*  73 */           jsonObject.put("tagIds", new int[tagId]);
/*     */         }
/*     */       } catch (DBException e) {
/*  76 */         jsonObject.put("error", "1");
/*  77 */         logger.warn("add tag failed", e);
/*     */       }
/*  79 */       out.println(jsonObject);
/*  80 */       out.flush();
/*  81 */       out.close();
/*  82 */       return;
/*     */     }
/*     */ 
/*  85 */     TagManager manager = new TagManager();
/*     */     try {
/*  87 */       if ("1".equals(type))
/*     */       {
/*  89 */         List updateCustomerIds = manager.addAll(tagId, 
/*  90 */           customerIds, companyId, userId);
/*  91 */         if ((updateCustomerIds != null) && (updateCustomerIds.size() > 0)) {
/*  92 */           jsonObject.put("error", "0");
/*  93 */           jsonObject.put("updateCustomerIds", 
/*  94 */             updateCustomerIds.toArray());
/*     */         } else {
/*  96 */           jsonObject.put("error", "1");
/*     */         }
/*     */       }
/*     */       else {
/* 100 */         int num = manager.add(tagId, customerId, companyId, userId);
/* 101 */         if (num > 0)
/* 102 */           jsonObject.put("error", "0");
/*     */         else
/* 104 */           jsonObject.put("error", "1");
/*     */       }
/*     */     }
/*     */     catch (DBException e)
/*     */     {
/* 109 */       jsonObject.put("error", "1");
/*     */     }
/* 111 */     out.println(jsonObject);
/* 112 */     out.flush();
/* 113 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.AddCustomerTagRelation
 * JD-Core Version:    0.6.1
 */